<!DOCTYPE html>
<html>
<head>
    <title>Hacker Terminal</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
    <style>
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            background-color: #000;
            color: #0f0;
            font-family: 'Courier New', monospace;
            overflow: hidden;
        }
        .hidden { display: none; }
        .container, .login-container {
            display: flex;
            flex-direction: column;
            height: 100vh;
            justify-content: center;
            align-items: center;
        }
        .login-form {
            background: rgba(0, 0, 0, 0.8);
            padding: 20px;
            border: 1px solid #0f0;
            box-shadow: 0 0 10px #0f0;
        }
        input[type="text"], input[type="password"], input[type="checkbox"] {
            width: 200px;
            padding: 10px;
            margin-bottom: 10px;
            background-color: #000;
            border: 1px solid #0f0;
            color: #0f0;
        }
        .login-button {
            width: 100%;
            padding: 10px;
            background-color: #0f0;
            color: #000;
            cursor: pointer;
            font-weight: bold;
        }
        .terminal, .command-input, .status-bar {
            display: none;
        }
        .checkbox-container {
            color: #0f0;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        label {
            margin-left: 5px;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <form class="login-form">
            <input type="text" id="hostname" placeholder="Hostname" value="pehost" required>
            <input type="text" id="server" placeholder="Server Address" value="10.10.1.109" required>
            <input type="text" id="port" placeholder="Port" value="2224" required>
            <input type="text" id="username" placeholder="Username" required>
            <input type="password" id="password" placeholder="Password" required>
            <div class="checkbox-container">
                <input type="checkbox" id="remember-me">
                <label for="remember-me">Remember Me</label>
            </div>
            <button type="submit" class="login-button">Connect</button>
        </form>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            $('.login-form').on('submit', function(e) {
                e.preventDefault();
                const hostname = $('#hostname').val();
                const server = $('#server').val();
                const port = $('#port').val();
                const username = $('#username').val();
                const password = $('#password').val();
                const rememberMe = $('#remember-me').is(':checked');

                // Send login details to the server
                $.ajax({
                    url: '/connect',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({ server, port, username, password, rememberMe }),
                    success: function(response) {
                        if (response.success) {
                            window.location.href = '/'; // Redirect to the root path
                        } else {
                            alert('Login failed. Please check your credentials.');
                        }
                    },
                    error: function() {
                        alert('Connection error. Please try again later.');
                    }
                });
            });
        });
    </script>
</body>
</html>
